﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace POS
{
    public partial class OrderEntryScreen : DevExpress.XtraEditors.XtraUserControl
    {
        public static OrderEntryScreen _Main;
        int r = 1;
        public OrderEntryScreen()
        {
            InitializeComponent();
            _Main = this;
            listView1.BackColor = this.BackColor;
            listView1.ForeColor = this.ForeColor;

            lblServerName.Text = StaticProperties.ServerName;
            lblTableName.Text = StaticProperties.TableName;
        }

        private void OrderEntryScreen_Load(object sender, EventArgs e)
        {
            StaticProperties.ReceiptNo = Convert.ToInt32(StaticProperties.ReceiptNoGenerator());

            lblReceiptNo.Text = StaticProperties.ReceiptNo.ToString();

            panelControl1.Controls.Add(new MenuItemsButtons("DRINK"));
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            MainProgram._Main.panelControl1.Controls.Clear();
            MainProgram._Main.panelControl1.Controls.Add(new HomeScreen());
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (btnSendTicket.Text == "SEND TICKET")
                {
                    //MessageBox.Show(DataTableClass.Receipt.Rows.Count.ToString());

                    try
                    {
                        DataRow newCustomersRow = DataTableClass.Receipt.NewRow();//dataSet1.Tables["Customers"].NewRow();

                        //newCustomersRow["EntryNo"] = lblReceiptNo.Text;
                        newCustomersRow["ReceiptNo"] = lblReceiptNo.Text;
                        newCustomersRow["ReceiptDate"] = DateTime.Now.ToShortDateString();
                        newCustomersRow["ReceiptTableName"] = lblTableName.Text;
                        newCustomersRow["ReceiptServerID"] = StaticProperties.ServerID.ToString();
                        newCustomersRow["ReceiptSubTotal"] = decimal.Parse(lblSubTotal.Text, System.Globalization.NumberStyles.Currency);
                        newCustomersRow["ReceiptTaxTotal"] = "0.00";
                        newCustomersRow["ReceiptAutoGrat"] = "0.00";
                        newCustomersRow["ReceiptGrat"] = "0.00";
                        newCustomersRow["ReceiptDiscountTotal"] = "0.00";
                        newCustomersRow["ReceiptGrandTotal"] = "0.00";


                        DataTableClass.Receipt.Rows.Add(newCustomersRow);
                    }
                    catch (Exception E)
                    {
                        MessageBox.Show(E.ToString());
                    }
                    

                    r = Convert.ToInt32(lblReceiptNo.Text);
                    foreach (ListViewItem item in listView1.Items)
                    {
                        DataRow newCustomersRow = DataTableClass.ReceiptData.NewRow();//dataSet1.Tables["Customers"].NewRow();

                        //newCustomersRow["EntryNo"] = r.ToString();
                        newCustomersRow["ReceiptNo"] = lblReceiptNo.Text;
                        newCustomersRow["ReceiptQty"] = item.SubItems[0].Text;
                        newCustomersRow["ReceiptDescription"] = item.SubItems[1].Text;

                        string total = item.SubItems[2].Text.Replace("$", "");
                        newCustomersRow["ReceiptItemTotal"] = total;

                        DataTableClass.ReceiptData.Rows.Add(newCustomersRow);
                    }
                }
                else if (btnSendTicket.Text == "ADD TO TICKET")
                {

                }
            }
            catch(Exception E)
            {
                MessageBox.Show(E.Message);
            }
            finally
            {
                //MessageBox.Show(DataTableClass.Receipt.Rows.Count.ToString());
                //DataTableClass.SendDataToSqlServer(DataTableClass.Receipt.TableName);
                MainProgram._Main.panelControl1.Controls.Clear();
                MainProgram._Main.panelControl1.Controls.Add(new HomeScreen());
            }
        }
    }
}
